﻿mod json_content;
mod json_parser;
mod json_repair_error;
mod string_utils;

use pyo3::prelude::*;
use pyo3::types::IntoPyDict;

pub fn invoke_repair_json(json_str: &str) ->  PyResult<String >  {
    Python::with_gil(|py| {
        // 获取 sys 模块
        let sys = py.import("sys")?;

        // 获取当前模块所在的目录
        let current_dir = std::env::current_dir()?;
        let module_dir = current_dir.join("src/utils"); // 模块所在目录

        // 将模块所在目录添加到 sys.path
        let path_attr = sys.getattr("path")?;
        let path: Vec<String> = path_attr.extract()?;
        let mut new_path = path.clone();
        new_path.push(module_dir.to_string_lossy().into_owned());
        sys.setattr("path", new_path)?;

        let mymodule = py.import("inspection")?;

        let func = mymodule.getattr("repair_json")?;
        let result: String = func.call1((json_str,) )?.extract()?;
        Ok(result)
    })
}
